home *** CD-ROM | disk | FTP | other *** search
/ Aminet 39 / Aminet 39 (2000)(Schatztruhe)[!][Oct 2000].iso / Aminet / misc / emu / flamingo.lha / Flamingo / sources / ecs.asm < prev    next >
Encoding:
Assembly Source File  |  2000-07-21  |  11.3 KB  |  600 lines

  1. ; ECS
  2. ; External Video Driver for
  3. ; Flaming Plus/4 emulator for the Amiga
  4. ;
  5. ; version 1.2
  6.  
  7.     MACHINE    68020
  8.  
  9.         INCDIR    Include:
  10.  
  11.     INCLUDE exec/types.i
  12.     INCLUDE    exec/memory.i
  13.     INCLUDE    exec/exec_lib.i
  14.     INCLUDE    utility/tagitem.i
  15.     INCLUDE    intuition/intuition.i
  16.     INCLUDE    intuition/intuition_lib.i
  17.     INCLUDE    intuition/screens.i
  18.     INCLUDE    graphics/graphics_lib.i
  19.     INCLUDE graphics/modeid.i
  20.     INCLUDE    graphics/rastport.i
  21.     INCLUDE    dos/dos.i
  22.     INCLUDE    dos/dos_lib.i
  23.     INCLUDE    libraries/asl.i
  24.     INCLUDE    libraries/asl_lib.i
  25.     INCLUDE    macros.i
  26.  
  27. ;*** Handler structure
  28.  
  29.  STRUCTURE vxd_handler,0
  30.   LONG intuibase
  31.   LONG graphbase
  32.   LONG dosbase
  33.   LONG aslbase
  34.   LONG myscr
  35.   LONG mywin
  36.   LONG planes
  37.   WORD xsize
  38.   WORD ysize
  39.   LONG emuscr
  40.   LONG scrmodereq
  41.   LONG screendim
  42.   WORD bytesperrow
  43.  LABEL    vxd_handler_SIZEOF
  44.  
  45.  STRUCTURE c2p,4
  46.   LONG C2PChunkyBufferAddress
  47.   LONG C2PPlanarBufferAddress
  48.   LONG C2PChunkyBufferWidth
  49.   LONG C2PChunkyBufferHeight
  50.   LONG C2PBitplaneByteWidth
  51.  LABEL c2p_SIZEOF
  52.  
  53. JSRLIB    MACRO
  54.     jsr    _LVO\1(a6)
  55.     ENDM
  56.  
  57. ;*** Let's begin
  58.  
  59.     moveq.l    #0,d0
  60.     rts
  61.  
  62.     dc.b "FLAMINGOXVD"
  63.     dc.b "2"
  64.  
  65.     dc.l Name
  66.     dc.l Author
  67.     dc.w 1
  68.     dc.w 2
  69.  
  70.     dc.l drv_Init
  71.     dc.l drv_Done
  72.     dc.l drv_Configure
  73.     dc.l drv_OpenScreen
  74.     dc.l drv_CloseScreen
  75.     dc.l drv_Refresh
  76.     dc.l 0            ;No PPC refresh
  77.  
  78. Name:    dc.b    "ECS External Video Driver",0
  79. Author:    dc.b    "Álmos Rajnai (original C2P by Ferenc Zavacki)",0
  80.  
  81.     EVEN
  82.  
  83. ;*** Functions
  84.  
  85. drv_Init:
  86.     movem.l    a0-a1,-(sp)    ;Saving infos
  87.     move.l  4.w,a6        ;Alloc memory for handler
  88.     move.l    #MEMF_PUBLIC|MEMF_CLEAR,d1
  89.     move.l    #vxd_handler_SIZEOF,d0
  90.     JSRLIB    AllocVec
  91.     movem.l    (sp)+,a0-a1    ;Recover infos
  92.         tst.l    d0
  93.     beq.b    .1        ;No mem
  94.     movea.l    d0,a2
  95.         move.l    (a0),graphbase(a2)    ;Saving graphics.library base
  96.         move.l    4(a0),dosbase(a2)    ;Saving dos.library base
  97.         move.l    8(a0),intuibase(a2)    ;Saving intuition.library base
  98.         move.l    16(a0),aslbase(a2)    ;Saving asl.library base
  99.         movem.l    d0,-(sp)
  100.  
  101.     move.l    dosbase(a2),a6        ;Reading config file
  102.     move.l    #configfile,d1        ;Config file is pretty simple:
  103.     move.l    #MODE_OLDFILE,d2    ;only a screenmode number
  104.     JSRLIB    Open
  105.     tst.l    d0
  106.     beq.b    .2            ;Failed open
  107.     move.l    d0,d1
  108.     move.l    (sp),a0
  109.     lea    screendim(a0),a0
  110.     move.l    a0,d2
  111.     moveq.l    #4,d3
  112.     movem.l    d0,-(sp)
  113.     JSRLIB    Read            ;Reading the 4 bytes
  114.     cmp.l    #4,d0
  115.     beq.b    .3
  116.     move.l    (sp),a0            ;Failed: set 0 instead garbage
  117.     move.l    #0,screendim(a0)
  118.  
  119. .3    movem.l    (sp)+,d1
  120.     JSRLIB    Close
  121.  
  122. .2    movem.l    (sp)+,d0
  123. .1    move.l    #err_nomem,d1        ;Ignored, if D0 not 0
  124.     rts                ;Result in D0 available for now
  125.  
  126. drv_Done:
  127.     movea.l    a0,a1
  128.     cmpa.l    #0,a1
  129.     beq.b    .1
  130.     move.l    4.w,a6
  131.     JSRLIB    FreeVec        ;Deallocate handler
  132. .1
  133.     rts
  134.  
  135. drv_Configure:            ;Configure
  136.                 ;A simple screenmode requester appears
  137.     movem.l    a0,-(sp)
  138.     move.l    screendim(a0),displayid
  139.     move.l    #ASL_ScreenModeRequest,d0    
  140.     move.l    aslbase(a0),a6
  141.     lea    asltags,a0
  142.     JSRLIB    AllocAslRequest
  143.     move.l    (sp),a0
  144.     move.l    d0,scrmodereq(a0)
  145.     tst.l    d0
  146.     bne.b    config2
  147.     lea    4(sp),sp
  148.     rts
  149.  
  150. config2:
  151.     move.l    d0,a0
  152.     suba.l    a1,a1
  153.     JSRLIB    AslRequest
  154.     tst.l    d0
  155.     beq.b    .1
  156.  
  157.     move.l    (sp),a1
  158.     move.l    scrmodereq(a1),a0
  159.     move.l    sm_DisplayID(a0),screendim(a1)
  160.  
  161.     move.l    dosbase(a1),a6        ;Writing config file
  162.     move.l    #configfile,d1        ;Config file is pretty simple:
  163.     move.l    #MODE_NEWFILE,d2    ;only a screenmode number
  164.     JSRLIB    Open
  165.     tst.l    d0
  166.     beq.b    .1            ;Failed open
  167.     move.l    d0,d1
  168.     move.l    (sp),a0
  169.     lea    screendim(a0),a0
  170.     move.l    a0,d2
  171.     moveq.l    #4,d3
  172.     movem.l    d0,-(sp)
  173.     JSRLIB    Write            ;Writing the 4 bytes
  174.  
  175.     movem.l    (sp)+,d1        ;We don't care too much on
  176.     JSRLIB    Close            ;success...
  177.  
  178. .1    movem.l    (sp)+,a0
  179.     move.l    aslbase(a0),a6
  180.     move.l    scrmodereq(a0),a0
  181.     JSRLIB    FreeAslRequest
  182.     rts
  183.  
  184. drv_OpenScreen:
  185.     movea.l a0,a5
  186.     move.w    (a1)+,xsize(a5)
  187.     move.w    (a1)+,ysize(a5)
  188.     move.l    screendim(a5),screenmode    ;screenmode from init
  189.  
  190.     moveq.l    #0,d0
  191.     move.l    d0,d1
  192.     move.w    xsize(a5),d0
  193.     move.w    ysize(a5),d1
  194.     mulu.w    d1,d0
  195.     move.l    #MEMF_PUBLIC|MEMF_CLEAR,d1
  196.     move.l    4.w,a6
  197.     JSRLIB    AllocVec
  198.     move.l    d0,emuscr(a5)        ;allocating emulator screen
  199.     beq.w    .1
  200.  
  201.     move.w    xsize(a5),width+2
  202.     move.w    ysize(a5),height+2
  203.         suba.l    a0,a0            ;No newscreen stuct
  204.         lea    scrtags,a1
  205.     movea.l    intuibase(a5),a6
  206.     JSRLIB    OpenScreenTagList
  207.     move.l    d0,myscr(a5)
  208.     beq.w    .1
  209.     move.l    d0,wscr
  210.     move.l    d0,a0
  211.     lea    sc_RastPort(a0),a0
  212.     movea.l    rp_BitMap(a0),a0
  213.     move.l    #BMA_FLAGS,d1
  214.     movea.l    graphbase(a5),a6
  215.     JSRLIB    GetBitMapAttr
  216.     and.l    #BMF_STANDARD|BMF_INTERLEAVED,d0
  217.     cmp.l    #BMF_STANDARD|BMF_INTERLEAVED,d0
  218.     beq.b    .3
  219.     movea.l    intuibase(a5),a6
  220.     move.l    myscr(a5),a0
  221.     JSRLIB    CloseScreen
  222.     moveq.l    #0,d0
  223.     move.l    d0,myscr(a5)
  224.     bra.b    .1
  225.  
  226. .3    move.w    xsize(a5),wwidth+2
  227.     move.w    ysize(a5),wheight+2
  228.     suba.l    a0,a0
  229.     lea    wintags,a1
  230.     movea.l    intuibase(a5),a6
  231.     JSRLIB    OpenWindowTagList
  232.     move.l    d0,mywin(a5)
  233.     beq.b    .1
  234.     movea.l    d0,a1
  235.     move.l  wd_RPort(a1),a0
  236.     move.l    rp_BitMap(a0),a0
  237.     move.l    bm_Planes(a0),planes(a5)
  238.     move.w    bm_BytesPerRow(a0),d0
  239.     and.l    #$ffff,d0
  240.     moveq.l    #3,d1
  241.     divu.w    d1,d0
  242.     move.w    d0,bytesperrow(a5)
  243.     move.l  wd_UserPort(a1),d0    ;IDCMP port
  244.     move.l    emuscr(a5),d2        ;chunky buffer
  245.  
  246. .1    move.l    #err_noscr,d1
  247.     moveq.l    #0,d3            ;no chunky modulo
  248.     rts
  249.  
  250. drv_CloseScreen:
  251.     move.l    a0,a5
  252.     move.l    intuibase(a5),a6
  253.     move.l    mywin(a5),a0
  254.     cmpa.l    #0,a0
  255.     beq.b    .1
  256.     JSRLIB    CloseWindow
  257.  
  258. .1    move.l    myscr(a5),a0
  259.     cmpa.l    #0,a0
  260.     beq.b    .2
  261.     JSRLIB    CloseScreen
  262.  
  263. .2    movea.l    emuscr(a5),a1
  264.         cmpa.l    #0,a1
  265.     beq.b    .3
  266.     move.l    4.w,a6
  267.     JSRLIB    FreeVec        ;Deallocate translated palette
  268.  
  269. .3    moveq.l    #0,d0
  270.     move.l    d0,emuscr(a5)    ;They were already freed
  271.     move.l    d0,myscr(a5)
  272.     move.l    d0,mywin(a5)
  273.  
  274.     rts
  275.  
  276. drv_Refresh:
  277.     SUBA.L    #c2p_SIZEOF,A7        ;Storing all data on stack
  278.  
  279.     MOVE.L    (emuscr,A0),(C2PChunkyBufferAddress,A7)
  280.     MOVE.L    (planes,A0),(C2PPlanarBufferAddress,A7)
  281.     MOVEQ.L    #0,D0
  282.     MOVE.W    (xsize,A0),D0
  283.     MOVE.L    D0,(C2PChunkyBufferWidth,A7)
  284.     MOVE.W    (ysize,A0),D0
  285.     MOVE.L    D0,(C2PChunkyBufferHeight,A7)
  286.     MOVE.W    (bytesperrow,A0),D0
  287.     MOVE.L    D0,(C2PBitplaneByteWidth,A7)
  288.  
  289.  
  290.         MOVE.L  (C2PChunkyBufferAddress,A7),A0
  291.         MOVE.L  (C2PChunkyBufferWidth,A7),D0
  292.         MULU.L  (C2PChunkyBufferHeight,A7),D0
  293.         LEA     (A0,D0.L),A2
  294.  
  295.         MOVE.L  (C2PPlanarBufferAddress,A7),A1
  296.  
  297.         MOVE.L  (C2PChunkyBufferWidth,A7),D6
  298.         LSR.L   #5,D6
  299.  
  300.         MOVE.L  (C2PBitplaneByteWidth,A7),D7
  301.  
  302.         MOVE.L  #$70707070,D5
  303.  
  304.         MOVE.L  (A0)+,D0
  305.         AND.L   D5,D0
  306.         MOVE.L  (A0)+,D1
  307.         AND.L   D5,D1
  308.         LSR.L   #4,D1
  309.         OR.L    D1,D0
  310.  
  311.         MOVE.L  (A0)+,D1
  312.         AND.L   D5,D1
  313.         MOVE.L  (A0)+,D2
  314.         AND.L   D5,D2
  315.         LSR.L   #4,D2
  316.         OR.L    D2,D1
  317.  
  318.         MOVE.L  (A0)+,D2
  319.         AND.L   D5,D2
  320.         MOVE.L  (A0)+,D3
  321.         AND.L   D5,D3
  322.         LSR.L   #4,D3
  323.         OR.L    D3,D2
  324.  
  325.         MOVE.L  (A0)+,D3
  326.         AND.L   D5,D3
  327.         MOVE.L  (A0)+,D4
  328.         AND.L   D5,D4
  329.         LSR.L   #4,D4
  330.         OR.L    D4,D3
  331.  
  332.         MOVE.W  D2,D4
  333.         MOVE.W  D0,D2
  334.         SWAP    D2
  335.         MOVE.W  D2,D0
  336.         MOVE.W  D4,D2
  337.  
  338.         MOVE.W  D3,D4
  339.         MOVE.W  D1,D3
  340.         SWAP    D3
  341.         MOVE.W  D3,D1
  342.         MOVE.W  D4,D3
  343.  
  344.         MOVE.L  #$00FF00FF,D5
  345.  
  346.         MOVE.L  D1,D4
  347.         LSR.L   #8,D4
  348.         EOR.L   D0,D4
  349.         AND.L   D5,D4
  350.         EOR.L   D4,D0
  351.         LSL.L   #8,D4
  352.         EOR.L   D4,D1
  353.  
  354.         MOVE.L  D3,D4
  355.         LSR.L   #8,D4
  356.         EOR.L   D2,D4
  357.         AND.L   D5,D4
  358.         EOR.L   D4,D2
  359.         LSL.L   #8,D4
  360.         EOR.L   D4,D3
  361.  
  362.         MOVE.L  #$33333333,D5
  363.  
  364.         MOVE.L  D2,D4
  365.         LSR.L   #2,D4
  366.         EOR.L   D0,D4
  367.         AND.L   D5,D4
  368.         EOR.L   D4,D0
  369.         LSL.L   #2,D4
  370.         EOR.L   D4,D2
  371.  
  372.         MOVE.L  D3,D4
  373.         LSR.L   #2,D4
  374.         EOR.L   D1,D4
  375.         AND.L   D5,D4
  376.         EOR.L   D4,D1
  377.         LSL.L   #2,D4
  378.         EOR.L   D4,D3
  379.  
  380.         MOVE.L  #$55555555,D5
  381.  
  382.         MOVE.L  D1,D4
  383.         LSR.L   #1,D4
  384.         EOR.L   D0,D4
  385.         AND.L   D5,D4
  386.         EOR.L   D4,D0
  387.         LSL.L   #1,D4
  388.         EOR.L   D4,D1
  389.  
  390.         MOVE.L  D3,D4
  391.         LSR.L   #1,D4
  392.         EOR.L   D2,D4
  393.         AND.L   D5,D4
  394.         EOR.L   D4,D2
  395.         LSL.L   #1,D4
  396.         EOR.L   D4,D3
  397.  
  398.         MOVE.L  D0,A3
  399.         MOVE.L  D1,A4
  400.         MOVE.L  D2,A5
  401.         MOVE.L  D3,A6
  402.  
  403. .1      MOVE.L  #$70707070,D5
  404.  
  405.         MOVE.L  (A0)+,D0
  406.         AND.L   D5,D0
  407.         MOVE.L  (A0)+,D1
  408.         AND.L   D5,D1
  409.         LSR.L   #4,D1
  410.         OR.L    D1,D0
  411.  
  412.         MOVE.L  (A0)+,D1
  413.         AND.L   D5,D1
  414.         MOVE.L  (A0)+,D2
  415.         AND.L   D5,D2
  416.         LSR.L   #4,D2
  417.         OR.L    D2,D1
  418.  
  419.         MOVE.L  (A0)+,D2
  420.         AND.L   D5,D2
  421.         MOVE.L  (A0)+,D3
  422.         AND.L   D5,D3
  423.         LSR.L   #4,D3
  424.         OR.L    D3,D2
  425.  
  426.         MOVE.L  (A0)+,D3
  427.         AND.L   D5,D3
  428.         MOVE.L  (A0)+,D4
  429.         AND.L   D5,D4
  430.         LSR.L   #4,D4
  431.         OR.L    D4,D3
  432.  
  433.         MOVE.L  A6,(A1)+
  434.  
  435.         MOVE.W  D2,D4
  436.         MOVE.W  D0,D2
  437.         SWAP    D2
  438.         MOVE.W  D2,D0
  439.         MOVE.W  D4,D2
  440.  
  441.         MOVE.W  D3,D4
  442.         MOVE.W  D1,D3
  443.         SWAP    D3
  444.         MOVE.W  D3,D1
  445.         MOVE.W  D4,D3
  446.  
  447.         MOVE.L  #$00FF00FF,D5
  448.  
  449.         MOVE.L  D1,D4
  450.         LSR.L   #8,D4
  451.         EOR.L   D0,D4
  452.         AND.L   D5,D4
  453.         EOR.L   D4,D0
  454.         LSL.L   #8,D4
  455.         EOR.L   D4,D1
  456.  
  457.         MOVE.L  A5,(-4,A1,D7.L)
  458.  
  459.         MOVE.L  D3,D4
  460.         LSR.L   #8,D4
  461.         EOR.L   D2,D4
  462.         AND.L   D5,D4
  463.         EOR.L   D4,D2
  464.         LSL.L   #8,D4
  465.         EOR.L   D4,D3
  466.  
  467.         MOVE.L  #$33333333,D5
  468.  
  469.         MOVE.L  D2,D4
  470.         LSR.L   #2,D4
  471.         EOR.L   D0,D4
  472.         AND.L   D5,D4
  473.         EOR.L   D4,D0
  474.         LSL.L   #2,D4
  475.         EOR.L   D4,D2
  476.  
  477.         MOVE.L  A4,(-4,A1,D7.L*2)
  478.  
  479.         MOVE.L  D3,D4
  480.         LSR.L   #2,D4
  481.         EOR.L   D1,D4
  482.         AND.L   D5,D4
  483.         EOR.L   D4,D1
  484.         LSL.L   #2,D4
  485.         EOR.L   D4,D3
  486.  
  487.         MOVE.L  #$55555555,D5
  488.  
  489.         MOVE.L  D1,D4
  490.         LSR.L   #1,D4
  491.         EOR.L   D0,D4
  492.         AND.L   D5,D4
  493.         EOR.L   D4,D0
  494.         LSL.L   #1,D4
  495.         EOR.L   D4,D1
  496.  
  497.         MOVE.L  D3,D4
  498.         LSR.L   #1,D4
  499.         EOR.L   D2,D4
  500.         AND.L   D5,D4
  501.         EOR.L   D4,D2
  502.         LSL.L   #1,D4
  503.         EOR.L   D4,D3
  504.  
  505.         MOVE.L  D0,A3
  506.         MOVE.L  D1,A4
  507.         MOVE.L  D2,A5
  508.         MOVE.L  D3,A6
  509.  
  510.         SUBQ.L   #1,D6
  511.         BNE.B   .2
  512.  
  513.         MOVE.L  (C2PChunkyBufferWidth,A7),D6
  514.         LSR.L   #3,D6
  515.         SUB.L   D6,A1
  516.         LSR.L   #2,D6
  517.         LEA     (A1,D7.L*4),A1
  518.     SUBA.L    D7,A1
  519.  
  520. .2      CMP.L   A2,A0
  521.         BNE     .1
  522.  
  523.     MOVE.L    C2PChunkyBufferAddress(A7),D0    ;giving back chunky buffer
  524.         ADDA.L    #c2p_SIZEOF,A7
  525.     
  526.         RTS
  527.  
  528.     EVEN
  529.  
  530. ;*** Constants
  531.  
  532. scrtags:
  533.     dc.l    SA_Width
  534. width:    dc.l    0
  535.     dc.l    SA_Height
  536. height:    dc.l    0
  537.     dc.l    SA_Depth,3
  538.     dc.l    SA_Colors32,palette32
  539.     dc.l    SA_Title,scrtitle
  540.     dc.l    SA_ShowTitle,FALSE
  541.     dc.l    SA_DisplayID
  542. screenmode:
  543.     dc.l    0
  544.     dc.l    SA_Interleaved,TRUE
  545.     dc.l    SA_Type,CUSTOMSCREEN
  546.     dc.l    SA_AutoScroll,TRUE
  547.     dc.l    SA_Overscan,OSCAN_STANDARD
  548.     dc.l    SA_Quiet,TRUE
  549.     dc.l    TAG_DONE
  550.  
  551. wintags:
  552.     dc.l    WA_Left,0
  553.     dc.l    WA_Top,0
  554.     dc.l    WA_Width
  555. wwidth:    dc.l    0
  556.     dc.l    WA_Height
  557. wheight:    dc.l    0
  558.     dc.l    WA_IDCMP,IDCMP_RAWKEY
  559.     dc.l    WA_Title,0
  560.     dc.l    WA_Backdrop,TRUE
  561.     dc.l    WA_RMBTrap,TRUE
  562.     dc.l    WA_Borderless,TRUE
  563.     dc.l    WA_NoCareRefresh,TRUE
  564.     dc.l    WA_CustomScreen
  565. wscr:    dc.l    0
  566.     dc.l    WA_SimpleRefresh,TRUE
  567.     dc.l    WA_Activate,TRUE
  568.     dc.l    TAG_DONE
  569.  
  570. asltags:
  571.     dc.l    ASLSM_TitleText,configwintxt
  572.     dc.l    ASLSM_InitialDisplayID
  573. displayid:
  574.     dc.l    0
  575.     dc.l    TAG_DONE
  576.  
  577. palette32:
  578.     dc.w    8,0
  579.  
  580. offs    SET    $30
  581.     REPT    8
  582.     dc.l    offs<<24,offs<<24,offs<<24
  583. offs    SET    offs+$1a
  584.     ENDR
  585.     dc.l    0,0,0,0
  586.  
  587. scrtitle:    dc.b    'Flamingo Plus/4 emulator screen',0
  588.  
  589. configwintxt:    dc.b    'Choose desired screenmode',0
  590.  
  591. configfile:    dc.b    'ecs.cfg',0
  592.  
  593. ;*** Errors
  594.  
  595. err_nomem:
  596.     dc.b    'Ran out of memory',0
  597. err_noscr:
  598.     dc.b    'Cannot open screen',0
  599.  
  600.